var app = getApp();
var req = require("../../utils/req.js");
var utils = require("../../utils/util.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: '',
    qrcode: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  getMoney: function(e) {
    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于两位数字
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      money: money
    })
  },
  /**
   * 设置金额
   */
  setMoney: function(e) {
    var that = this;
    var money = this.data.money;
    if(money==''||money==0){
      wx.showToast({
        title: '请输入正确的金额',
        icon: 'none'
      })
      return;
    }else if (parseInt(money) > 10000 || parseInt(money) < 0) {
      wx.showToast({
        title: '金额不能超过10000',
        icon:'none'
      })
      return;
    }
    var storeId = app.globalData.storeId;
    var configUrl = app.config.url;
    console.log(storeId);
    console.log(e)
    var data = {
      money: money,
      formId: e.detail.formId
    };
    console.log(money);
    req.storeRequest("请稍等", "POST",url.qrcode['createPaymentCode'], storeId, data, function back(res) {
      console.log(res.data);
      that.setData({
        qrcode: res.data
      })
      wx.navigateTo({
        url: '../setMoneryWeChat/setMoneryWeChat?qrcode=' + that.data.qrcode,
      })
    });
  }
})